# _*_ coding: utf-8 _*_
# .@FileName:LegSrc
# .@Data....:2025-04-06 : 11 : 54
# .@Aurhor..:LiuJingYu
"""
launch:
from __future__ import unicode_literals, print_function
import maya.cmds as mc
"""
import maya.cmds as cmds

# 选择一根骨骼链
selected_joints = cmds.ls(selection=True, type='joint')
if not selected_joints:
    cmds.warning("请选择一根骨骼链。")
else:
    # 复制骨骼链
    fk_joints = cmds.duplicate(selected_joints, name=[joint.replace("_L_", "_L_FK_") for joint in selected_joints])
    ik_joints = cmds.duplicate(selected_joints, name=[joint.replace("_L_", "_L_IK_") for joint in selected_joints])

    # 旋转约束设置
    for i in range(len(selected_joints)):
        #cmds.parentConstraint(fk_joints[i], ik_joints[i], selected_joints[i], maintainOffset=True, weight=1)
        constraint = cmds.orientConstraint(fk_joints[i], ik_joints[i], selected_joints[i], maintainOffset=False)
        cmds.setAttr(f'{constraint[0]}.interpType', 2)

    # 创建IK手柄
    # Rotate plane solver
    ikHandle_l_foot_1 = cmds.ikHandle(startJoint=ik_joints[0], endEffector=ik_joints[2], solver='ikRP2Bsolver',
                                      name='ikHandle_l_foot_1')
    # Single chain solver
    ikHandle_l_ball_1 = cmds.ikHandle(startJoint=ik_joints[2], endEffector=ik_joints[3], solver='ikSCsolver',
                                      name='ikHandle_l_ball_1')
    ikHandle_l_toe_1 = cmds.ikHandle(startJoint=ik_joints[3], endEffector=ik_joints[4], solver='ikSCsolver',
                                     name='ikHandle_l_toe_1')

    print("IK FK融合切换设置完成。")